package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.PlaceDAO;
import org.millioncall.yueyoga.admin.model.Place;

public class PlaceDAOImpl extends BaseDao implements PlaceDAO {

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return 0;
	}

	@Override
	public int insert(Place record) {
		return this.getPagableSqlSessionTemplate().insert("insertPlace", record);
	}

	@Override
	public int insertSelective(Place record) {
		return this.getPagableSqlSessionTemplate().insert("insertSelective", record);
	}

	@Override
	public Place selectByPrimaryKey(Integer id) {
		return this.getPagableSqlSessionTemplate().selectOne("selectByPrimaryKey",id);
	}

	@Override
	public int updateByPrimaryKeySelective(Place record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(Place record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Place> findAll(Map<String, Object> map) {
		PreparedQuery<Place> pq = this.getPagableSqlSessionTemplate().findAll("findAllPlace", map);
		List<Place> list = pq.list();
		return list;
	}

	@Override
	public Place findPlaceById(Integer id) {
		return this.getPagableSqlSessionTemplate().selectOne("findPlaceById",id);
	}

	@Override
	public PaginatedList<Place> getPlaseInPage(int start, int pageSize) {
		try {
			PreparedQuery<Place> pq = this.getPagableSqlSessionTemplate()
					.findAll("getPlaseInPage");
			PaginatedList<Place> pl = pq.list(new PaginateParams(
					new StartLimitPairImpl(start, pageSize)));
			return pl;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void deletePlaseByIds(Integer[] deids) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < deids.length; i++) {
			map.put("id", deids[i]);
			this.getPagableSqlSessionTemplate().delete("deletePlaseById", map);
		}
	}

	@Override
	public int updatePlace(Place place) {
		return this.getPagableSqlSessionTemplate().insert("updatePlace", place);
	}

	@Override
	public PaginatedList<Place> getPlaseInPage(int start, int pageSize,
			Map<String, Object> map) {
		try {
			PreparedQuery<Place> pq = this.getPagableSqlSessionTemplate()
					.findAll("getPlaseInPage",map);
			PaginatedList<Place> pl = pq.list(new PaginateParams(
					new StartLimitPairImpl(start, pageSize)));
			return pl;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public List<Place> findAllByOrganizationId(Map<String, Object> map) {
		PreparedQuery<Place> pq = this.getPagableSqlSessionTemplate().findAll("findAllPlaceByOrganizationId", map);
		return pq.list();
	}

}
